package org.shoukaiseki.kakaroto.entity;


import org.shoukaiseki.kakaroto.Interface.DictTypeEnumData;
import org.shoukaiseki.kakaroto.enums.DictDataCssClass;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 字典枚举类使用该字段作为存放值的容器
 */
public class BaseDictEnum implements DictTypeEnumData {


    private Object value;

    private String label;

    //已经使用枚举顺序自动编号
    private int sort=0;

    private String remark="";

    private char status='0';

    /**
     * true: 忽略插入到字典
     * @return
     */
    private boolean ignoreInsert=false;

    //显示属性(颜色等)
    private DictDataCssClass cssClass;

    public BaseDictEnum(){

    }

    public BaseDictEnum(Object value, String label) {
        this(value, label, 0);
    }

    public BaseDictEnum(Object value, String label, int sort) {
        this.value = value;
        this.label = label;
        this.sort = sort;
    }

    public BaseDictEnum(Object value, String label, String remark) {
        this(value, label, 0, remark);
    }

    public BaseDictEnum(Object value, String label, int sort, String remark) {
        this(value, label, sort, remark, '0');
    }

    public BaseDictEnum(Object value, String label, int sort, String remark, char status) {
        this.value = value;
        this.label = label;
        this.sort = sort;
        this.remark = remark;
        this.status=status;
    }

    public BaseDictEnum(Integer value, String label, int sort) {
        this.value = value;
        this.label = label;
        this.sort = sort;
    }

    public BaseDictEnum(Integer value, String label, String remark) {
        this(value, label, value, remark);
    }

    public BaseDictEnum(Integer value, String label, int sort, String remark) {
        this(value, label, sort, remark, '0');
    }

    public BaseDictEnum(Integer value, String label, int sort, String remark, char status) {
        this.value = value;
        this.label = label;
        this.sort = sort;
        this.remark = remark;
        this.status=status;
    }



    @Override
    public String getValueString() {
        if (Objects.isNull(value)) {
            return null;
        }
        return this.value.toString();
    }

    @Override
    public Integer getValueInteger() {
        return DictTypeEnumData.super.getValueInteger();
    }

    @Override
    public String getLabel() {
        return label;
    }

    @Override
    public int getSort() {
        return sort;
    }

    @Override
    public String getRemark() {
        return remark;
    }

    @Override
    public String getStatus() {
        return String.valueOf(status);
    }


    @Override
    public boolean isIgnoreInsert() {
        return ignoreInsert;
    }

    @Override
    public DictDataCssClass getCssClass() {
        return cssClass;
    }

    public List<BaseDictEnum> newListAutoSort(BaseDictEnum... dictEnums){
        List<BaseDictEnum> list = new ArrayList<>();
        for (int i = 0; i < dictEnums.length; i++) {
            BaseDictEnum dictEnum=dictEnums[i];
            dictEnum.sort=(i+1)*10;
            list.add(dictEnum);
        }
        return list;
    }


    public Object getValue() {
        return value;
    }

    public BaseDictEnum setValueAndLabel(String str) {
        this.value = str;
        this.label = str;
        return this;
    }

    public BaseDictEnum setValue(Object value) {
        this.value = value;
        return this;
    }

    public BaseDictEnum setLabel(String label) {
        this.label = label;
        return this;
    }

    public BaseDictEnum setSort(int sort) {
        this.sort = sort;
        return this;
    }

    public BaseDictEnum setRemark(String remark) {
        this.remark = remark;
        return this;
    }

    public BaseDictEnum setStatus(char status) {
        this.status = status;
        return this;
    }

    public BaseDictEnum setCssClass(DictDataCssClass cssClass) {
        this.cssClass = cssClass;
        return this;
    }

    /**
     * @param ignoreInsert      true: 忽略插入到字典,已插入不会删除
     * @return
     */
    public BaseDictEnum setIgnoreInsert(boolean ignoreInsert) {
        this.ignoreInsert = ignoreInsert;
        return this;
    }
}
